package com.wang.myapplication.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.wang.myapplication.R;
import com.wang.myapplication.network.bean.GlobalConfigResponse;
import com.wang.myapplication.network.bean.Userinfo;
import com.wang.myapplication.network.bean.WildConfigResponse;

public class MyApp extends Application {
    private static final String TAG = "MyApp";
    private static MyApp mMyApp;
    private GlobalConfigResponse mGlobalConfigResponse;
    private WildConfigResponse mWildConfigResponse;
    private GlobalConfigResponse.Companys mCompanys;
    private Userinfo mUserinfo;
    //上拉刷新 下拉加载的控件
    static {//static 代码段可以防止内存泄露
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//全局设置主题颜色
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mMyApp = this;
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                Log.d(TAG, "onActivityCreated() called with: activity = [" + activity + "], savedInstanceState = [" + savedInstanceState + "]");

            }

            @Override
            public void onActivityStarted(Activity activity) {
                Log.d(TAG, "onActivityStarted() called with: activity = [" + activity + "]");
            }

            @Override
            public void onActivityResumed(Activity activity) {
                Log.d(TAG, "onActivityResumed() called with: activity = [" + activity + "]");

            }

            @Override
            public void onActivityPaused(Activity activity) {
                Log.d(TAG, "onActivityPaused() called with: activity = [" + activity + "]");

            }

            @Override
            public void onActivityStopped(Activity activity) {
                Log.d(TAG, "onActivityStopped() called with: activity = [" + activity + "]");

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
                Log.d(TAG, "onActivitySaveInstanceState() called with: activity = [" + activity + "], outState = [" + outState + "]");

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                Log.d(TAG, "onActivityDestroyed() called with: activity = [" + activity + "]");

            }
        });
    }



    public synchronized static Context getAppContext() {
        return mMyApp;
    }
    public synchronized static MyApp getMyApp() {
        return mMyApp;
    }


    public synchronized GlobalConfigResponse getGlobalConfigResponse() {
        return mGlobalConfigResponse;
    }

    public void setGlobalConfigResponse(GlobalConfigResponse pGlobalConfigResponse) {
        mGlobalConfigResponse = pGlobalConfigResponse;
    }

    public synchronized WildConfigResponse getWildConfigResponse() {
        return mWildConfigResponse;
    }

    public void setWildConfigResponse(WildConfigResponse pWildConfigResponse) {
        mWildConfigResponse = pWildConfigResponse;
    }

    public GlobalConfigResponse.Companys getCompanys() {
        return mCompanys;
    }

    public void setCompanys(GlobalConfigResponse.Companys pCompanys) {
        mCompanys = pCompanys;
    }

    public synchronized Userinfo getUserinfo() {
        return mUserinfo;
    }

    public void setUserinfo(Userinfo pUserinfo) {
        mUserinfo = pUserinfo;
    }
}